/**
 Copyright will be fixed soon.
 Author: Hiroshi Ota.
 $Date: $
 $Revision: $
*/

#include "PWSound.h"

#ifdef _BRICKOS_
#include "c++/sound.h"
#endif

PWSound* PWSound::instance = 0;

PWSound* PWSound::create()
{
	if (instance==0) {
		instance = new PWSound();
	}
	return instance;
}

PWSound::PWSound()
{
}

PWSound::~PWSound()
{
}

#ifndef _BRICKOS_
PWSound::PWSound(ISimulatorControl *sc)
:simCon(sc),isPlaying(false)
{
}

PWSound* PWSound::create(ISimulatorControl* sc)
{
	if (instance==0) {
		instance = new PWSound(sc);
	}
	return instance;
}
#endif

void PWSound::play(const Note_t* notes)
{
	;
#ifdef _BRICKOS_
	note_t bNotes;
	bNotes.pitch = notes->pitch;
	bNotes.length = notes->length;
	Sound::play(&bNotes);
#else
	if (simCon!=0){
		simCon->play(notes->pitch, notes->length);
	}
	this->isPlaying=true;
#endif
}

int PWSound::playing()
{
	int result = 0;
#ifdef _BRICKOS_
	result = Sound::playing();
#else
	if (this->isPlaying) {
		result = 1;
	}
#endif
	return result;
}

void PWSound::beep()
{
#ifdef _BRICKOS_
	Sound::beep();
#else
	if (simCon!=0){
		simCon->beepSound();
	}
#endif
}

void PWSound::stop()
{
#ifdef _BRICKOS_
	Sound::stop();
#else
	if (simCon!=0){
		simCon->stopSound();
	}
	this->isPlaying=false;
#endif
}

void PWSound::duration(const unsigned int len)
{
#ifdef _BRICKOS_
	Sound::duration(len);
#else
	if (simCon!=0){
		simCon->setSoundDuration(len);
	}
#endif
}

void PWSound::internote(const unsigned int len)
{
#ifdef _BRICKOS_
	Sound::internote(len);
#else
	if (simCon!=0){
		simCon->setSoundInternote(len);
	}
#endif
}

